<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>长途调度单管理</title>
	<meta name="decorator" content="ani"/>
	<script type="text/javascript">
        var validateForm;
        var $table; // 父页面table表格id
        var $topIndex;//弹出窗口的 index
        function doSubmit(table, index){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            if(validateForm.form()){
                $table = table;
                $topIndex = index;
                jp.loading();
                $("#inputForm").submit();
                return true;
            }

            return false;
        }

        $(document).ready(function() {
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    jp.post("${ctx}/tms/dispatch/save",$('#inputForm').serialize(),function(data){
                        if(data.success){
                            $table.bootstrapTable('refresh');
                            jp.success(data.msg);
                            jp.close($topIndex);//关闭dialog

                        }else{
                            jp.error(data.msg);
                        }
                    })
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

            $('#dispatchDDate').datetimepicker({
                format: "YYYY-MM-DD HH:mm:ss"
            });
            $('#fetchDate').datetimepicker({
                format: "YYYY-MM-DD HH:mm:ss"
            });
        });

        function addRow(list, idx, tpl, row){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row
            }));
            $(list+idx).find("select").each(function(){
                $(this).val($(this).attr("data-value"));
            });
            $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                var ss = $(this).attr("data-value").split(',');
                for (var i=0; i<ss.length; i++){
                    if($(this).val() == ss[i]){
                        $(this).attr("checked","checked");
                    }
                }
            });
            $(list+idx).find(".form_datetime").each(function(){
                $(this).datetimepicker({
                    format: "YYYY-MM-DD HH:mm:ss"
                });
            });
        }
        function delRow(obj, prefix){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }
	</script>
</head>
<body class="bg-white">
<form:form id="inputForm" modelAttribute="dispatch" action="${ctx}/tms/dispatch/save" method="post" class="form-horizontal">
	<form:hidden path="id"/>
	<sys:message content="${message}"/>
	<table class="table table-bordered">
		<tbody>
		<tr>
			<td class="width-15 active"><label class="pull-right">调度单类型：</label></td>
			<td class="width-35">
				<form:select path="type" class="form-control ">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('dispatch_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</td>
			<td class="width-15 active"><label class="pull-right">调度单编号：</label></td>
			<td class="width-35">
				<form:input path="code" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">调度时间：</label></td>
			<td class="width-35">
				<p class="input-group">
				<div class='input-group form_datetime' id='dispatchDDate'>
					<input type='text'  name="dispatchDDate" class="form-control "  value="<fmt:formatDate value="${dispatch.dispatchDDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
					<span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
				</div>
				</p>
			</td>
			<td class="width-15 active"><label class="pull-right">取货时间：</label></td>
			<td class="width-35">
				<p class="input-group">
				<div class='input-group form_datetime' id='fetchDate'>
					<input type='text'  name="fetchDate" class="form-control "  value="<fmt:formatDate value="${dispatch.fetchDate}" pattern="yyyy-MM-dd HH:mm:ss"/>"/>
					<span class="input-group-addon">
			                        <span class="glyphicon glyphicon-calendar"></span>
			                    </span>
				</div>
				</p>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">车牌号：</label></td>
			<td class="width-35">
				<form:input path="truckNumber" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right">司机：</label></td>
			<td class="width-35">
				<form:input path="driver" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">司机电话：</label></td>
			<td class="width-35">
				<form:input path="driverPhone" htmlEscape="false" maxlength="64"    class="form-control  isTel"/>
			</td>
			<td class="width-15 active"><label class="pull-right">代收货款：</label></td>
			<td class="width-35">
				<form:input path="agencyPayment" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">运费：</label></td>
			<td class="width-35">
				<form:input path="freight" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right">附加费：</label></td>
			<td class="width-35">
				<form:input path="totalAppendCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">总成本费用：</label></td>
			<td class="width-35">
				<form:input path="totalCostCharge" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right">现付：</label></td>
			<td class="width-35">
				<form:input path="payCash" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>
		<tr>
			<td class="width-15 active"><label class="pull-right">提付：</label></td>
			<td class="width-35">
				<form:input path="payExtract" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right">回付：</label></td>
			<td class="width-35">
				<form:input path="payRound" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>

		<tr>
			<td class="width-15 active"><label class="pull-right">总重量：</label></td>
			<td class="width-35">
				<form:input path="totalWeight" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right">总体积：</label></td>
			<td class="width-35">
				<form:input path="totalVolume" htmlEscape="false" maxlength="64"    class="form-control "/>
			</td>
		</tr>

		<tr>
			<td class="width-15 active"><label class="pull-right">备注信息：</label></td>
			<td class="width-35">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255"    class="form-control "/>
			</td>
			<td class="width-15 active"><label class="pull-right"></label></td>
			<td class="width-35">
			</td>
		</tr>
		</tbody>
	</table>
	<div class="tabs-container">
		<ul class="nav nav-tabs">
			<li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">附加费用：</a>
			</li>
			<li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">订单明细：</a>
			</li>
		</ul>
		<div class="tab-content">
			<div id="tab-1" class="tab-pane fade in  active">
				<a class="btn btn-white btn-sm" onclick="addRow('#dispatchAppendList', dispatchAppendRowIdx, dispatchAppendTpl);dispatchAppendRowIdx = dispatchAppendRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
				<table class="table table-striped table-bordered table-condensed">
					<thead>
					<tr>
						<th class="hide"></th>
						<th>费用描述</th>
						<th>费用金额</th>
						<th>类型</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
					</thead>
					<tbody id="dispatchAppendList">
					</tbody>
				</table>
				<script type="text/template" id="dispatchAppendTpl">//<!--
				<tr id="dispatchAppendList{{idx}}">
					<td class="hide">
						<input id="dispatchAppendList{{idx}}_id" name="dispatchAppendList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="dispatchAppendList{{idx}}_delFlag" name="dispatchAppendList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td>
						<input id="dispatchAppendList{{idx}}_append" name="dispatchAppendList[{{idx}}].append" type="text" value="{{row.append}}" maxlength="64"  minlength="1"   class="form-control "/>
					</td>


					<td>
						<input id="dispatchAppendList{{idx}}_appendCharge" name="dispatchAppendList[{{idx}}].appendCharge" type="text" value="{{row.appendCharge}}"    class="form-control  isFloatGteZero"/>
					</td>


					<td>
						<input id="dispatchAppendList{{idx}}_appendType" name="dispatchAppendList[{{idx}}].appendType" type="text" value="{{row.appendType}}" maxlength="64"  minlength="1"   class="form-control "/>
					</td>


					<td>
						<textarea id="dispatchAppendList{{idx}}_remarks" name="dispatchAppendList[{{idx}}].remarks" rows="4" maxlength="255"  minlength="1"   class="form-control ">{{row.remarks}}</textarea>
					</td>

					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#dispatchAppendList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
				</script>
				<script type="text/javascript">
                    var dispatchAppendRowIdx = 0, dispatchAppendTpl = $("#dispatchAppendTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                    $(document).ready(function() {
                        var data = ${fns:toJson(dispatch.dispatchAppendList)};
                        for (var i=0; i<data.length; i++){
                            addRow('#dispatchAppendList', dispatchAppendRowIdx, dispatchAppendTpl, data[i]);
                            dispatchAppendRowIdx = dispatchAppendRowIdx + 1;
                        }
                    });
				</script>
			</div>
			<div id="tab-2" class="tab-pane fade">
				<a class="btn btn-white btn-sm" onclick="addRow('#dispatchDetailList', dispatchDetailRowIdx, dispatchDetailTpl);dispatchDetailRowIdx = dispatchDetailRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
				<table class="table table-striped table-bordered table-condensed">
					<thead>
					<tr>
						<th class="hide"></th>
						<th><font color="red">*</font>订单编号</th>
						<th><font color="red">*</font>提货地址</th>
						<th><font color="red">*</font>收货地址</th>
						<th><font color="red">*</font>包装规格</th>
						<th><font color="red">*</font>重量（KG）</th>
						<th><font color="red">*</font>方数（m³）</th>
						<th>备注信息</th>
						<th width="10">&nbsp;</th>
					</tr>
					</thead>
					<tbody id="dispatchDetailList">
					</tbody>
				</table>
				<script type="text/template" id="dispatchDetailTpl">//<!--
				<tr id="dispatchDetailList{{idx}}">
					<td class="hide">
						<input id="dispatchDetailList{{idx}}_id" name="dispatchDetailList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
						<input id="dispatchDetailList{{idx}}_delFlag" name="dispatchDetailList[{{idx}}].delFlag" type="hidden" value="0"/>
					</td>

					<td>
						<input id="dispatchDetailList{{idx}}_orderCode" name="dispatchDetailList[{{idx}}].orderCode" type="text" value="{{row.orderCode}}" maxlength="64"  minlength="1"   class="form-control required"/>
					</td>


					<td>
						<input id="dispatchDetailList{{idx}}_pickAddress" name="dispatchDetailList[{{idx}}].pickAddress" type="text" value="{{row.pickAddress}}" maxlength="64"  minlength="1"   class="form-control required"/>
					</td>


					<td>
						<input id="dispatchDetailList{{idx}}_receiveAddress" name="dispatchDetailList[{{idx}}].receiveAddress" type="text" value="{{row.receiveAddress}}" maxlength="64"  minlength="1"   class="form-control required"/>
					</td>


					<td>
						<input id="dispatchDetailList{{idx}}_packaging" name="dispatchDetailList[{{idx}}].packaging" type="text" value="{{row.packaging}}" maxlength="64"  minlength="1"   class="form-control required"/>
					</td>


					<td>
						<input id="dispatchDetailList{{idx}}_weight" name="dispatchDetailList[{{idx}}].weight" type="text" value="{{row.weight}}"    class="form-control required isFloatGtZero"/>
					</td>


					<td>
						<input id="dispatchDetailList{{idx}}_volume" name="dispatchDetailList[{{idx}}].volume" type="text" value="{{row.volume}}"    class="form-control required isFloatGtZero"/>
					</td>


					<td>
						<textarea id="dispatchDetailList{{idx}}_remarks" name="dispatchDetailList[{{idx}}].remarks" rows="4" maxlength="255"  minlength="1"   class="form-control ">{{row.remarks}}</textarea>
					</td>

					<td class="text-center" width="10">
						{{#delBtn}}<span class="close" onclick="delRow(this, '#dispatchDetailList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
					</td>
				</tr>//-->
				</script>
				<script type="text/javascript">
                    var dispatchDetailRowIdx = 0, dispatchDetailTpl = $("#dispatchDetailTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                    $(document).ready(function() {
                        var data = ${fns:toJson(dispatch.dispatchDetailList)};
                        for (var i=0; i<data.length; i++){
                            addRow('#dispatchDetailList', dispatchDetailRowIdx, dispatchDetailTpl, data[i]);
                            dispatchDetailRowIdx = dispatchDetailRowIdx + 1;
                        }
                    });
				</script>
			</div>
		</div>
	</div>
</form:form>
</body>
</html>